package com.wulee.notebook.db.db.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.wulee.notebook.bean.Note;

import java.util.List;

@Dao
public interface NoteDao {

    @Query("Select * from note")
    List<Note> getAll();

    @Query("Select * from note Where created_at = (:date)")
    Note loadByDate(long date);

    @Query("Select * from note  LIMIT (:size) OFFSET (:offset)")
//    @Query("Select * from note WHERE LENGTH (protects) > 5 LIMIT (:size) OFFSET (:offset)")
    List<Note> loadByPage(int offset, int size);

    @Query("Select * from note WHERE content LIKE (:like) LIMIT (:size) OFFSET (:offset)")
    List<Note> loadByLikePage(int offset, int size, String like);

    @Query("Select * from note Where created_at >= (:startDate) And created_at <= (:endDate)")
    List<Note> loadBy(long startDate, long endDate);

    @Query("Select * from note Where created_at >= (:startDate)")
    List<Note> loadFrom(long startDate);

//    @Query("Select * from note Where created_at >= (:startDate) And created_at <= (:endDate) And protects <> ''")
//    List<Note> loadLoveBy(long startDate, long endDate);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<Note> Notes);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insert(Note Note);

    @Delete
    void deleteAll(List<Note> Notes);

    @Delete
    int delete(Note... Notes);

//    @Delete
//    void clear();

    @Update
    void update(Note... Notes);

//    @Query("update videobean set id =:videoId where date=:uid")
//    void updateCustom(String videoId, int uid);
}
